package com.jy.api.domain;

import com.jy.api.signUpReq.StoreOrderSignUpReq;
import com.jy.api.util.UuidUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * Created by xiaohua on 2019/4/20.
 */
@Entity
@Data
@NoArgsConstructor
public class StockOrder {

    @Id
    private String id;

    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;

    private int count;

    private double amount;

    private Date payTime;

    private boolean payEnabled=false;

    private boolean sendEnabled=false;

    private String channel;

    private String address;

    private String mobile;

    private String name;

    private String status;

    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @Where(clause = "`enabled`=1")
    @OrderBy(value = "addTime")
    @JoinColumn(name = "stock_order_id")
    private List<StockOrderItem> items = new ArrayList<>();

    private String orderUserName;

    private boolean enabled=true;

    public StockOrder(StoreOrderSignUpReq req) {
        this.id = UuidUtil.getUuid();
        this.count = req.getCount();
        this.amount = req.getAmount();
        this.address = req.getAddress();
        this.mobile = req.getMobile();
        this.name = req.getName();
        this.orderUserName=req.getOrderUserName();
    }






}
